#include <REGX52.H>
#include "Delay.h"
#include "Key.h"
#include "LCD1602.h"
#include "AT24C02.h"


void main() {
	unsigned char key;
	unsigned int num = 0;
	
	LCD_Init();
	LCD_ShowNum(1, 1, num, 5);
	
	while (1) {
		
		key = Key();
		
		switch (key) {
			case 1:
				num++;
				LCD_ShowNum(1, 1, num, 5);
			break;
			case 2:
				num--;
				LCD_ShowNum(1, 1, num, 5);
			break;
			case 3:
				AT24C02_WriteByte(0, num / 256);
				Delay(5);
				AT24C02_WriteByte(1, num % 256);
				Delay(5);
				LCD_ShowString(2, 1, "Write OK");
				Delay(1000);
				LCD_ShowString(2, 1, "        ");
			break;
			case 4:
				num = AT24C02_ReadByte(0) << 8;
				num |= AT24C02_ReadByte(1);
				LCD_ShowNum(1, 1, num, 5);
				LCD_ShowString(2, 1, "Read OK");
				Delay(1000);
				LCD_ShowString(2, 1, "        ");
			break;
		}
	
	}

}